//
//  SearchUtils.swift
//  hello
//
//  Created by 赵康 on 2025/3/26.
//

import Foundation

  // 搜索工具类
struct SearchUtils {
  static func prepareSearchTerm(_ search: String) -> String {
    let cleaned = search.trimmingCharacters(in: .whitespaces)
    return cleaned.split(separator: " ")
      .map { "\($0)*" }
      .joined(separator: " ")
  }
  
  static func isShortChineseQuery(_ search: String) -> Bool {
      // 检查是否包含中文字符
    let chineseRegex = try! NSRegularExpression(pattern: "[\\p{Script=Han}]", options: [])
    let hasChineseChar = chineseRegex.firstMatch(
      in: search,
      options: [],
      range: NSRange(search.startIndex..., in: search)
    ) != nil
    
      // 如果是中文且长度小于等于2个字符，返回true
    return hasChineseChar && search.count <= 2
  }
}
